from google.appengine.ext import db

class NoteList (db.Model):
    """ Represents a list of notes. """
    name = db.StringProperty(required = False)
    created = db.DateTimeProperty(required = True)
    count = db.IntegerProperty(required = True)

class Note (db.Model):
    """ Model for a note """
    text = db.TextProperty(required = True)
    created = db.DateTimeProperty(auto_now_add = True)
    noteList = db.Reference(NoteList, required = True)
    url = db.LinkProperty(required = False)
    image = db.BlobProperty(required = False)

class Tag(db.Model):
    """ Model for a tag """
    text = db.StringProperty(required = True)
    notelist = db.ReferenceProperty(required = True)

class NoteOwner (db.Model):
    """ Access Control List for the notes """
    notes = db.ReferenceProperty(NoteList, required = True)
    owner = db.StringProperty(required = True)
    lastLogin = db.DateTimeProperty(auto_now = True)

class NoteTag (db.Model):
    """ Relation-entity for note and tag relation (m:n) """
    note = db.ReferenceProperty(Note)
    tag = db.ReferenceProperty(Tag)
